using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UI_Storage : MonoBehaviour
{
    private UI_StorageSlot[] storageSlots;
    private Inventory_Storage storage;
    private Inventory_Player playerInventory;

    [SerializeField] private UI_ItemSlotParent inventoryParent;
    [SerializeField] private UI_ItemSlotParent storageParent;
    [SerializeField] private UI_ItemSlotParent materialStorageParent;
    private void Awake()
    {
        storageSlots = GetComponentsInChildren<UI_StorageSlot>();
    }

    private void OnEnable()
    {
        UpdateUI();
    }

    //设置存储面板，当玩家和NPC_Smith交互时调用
    public void SetupStorageUI(Inventory_Storage storage)
    {
        this.storage = storage;
        playerInventory = storage.playerInventory;

        this.storage.OnInventoryChange += UpdateUI;

        UpdateUI();

        storageSlots = GetComponentsInChildren<UI_StorageSlot>();

        foreach (var slot in storageSlots)
            slot.SetStorageInventory(this.storage);
    }
    public void UpdateUI()
    {
        if (storage == null)
            return;

        inventoryParent.UpdateSlot(playerInventory.itemList);
        storageParent.UpdateSlot(storage.itemList);
        materialStorageParent.UpdateSlot(storage.materialStorageList);
    }
}
